from django.db import models
from user.models import User, FileStore
from software.models import SoftwareVersion, SoftwareGroup
from store.models import Store


# Create your models here.


class SoftwareOrder(models.Model):
    EXAMINESTATE = (
        ('0', u'等待审核'),
        ('1', u'审核通过'),
        ('2', u'审核未通过'),
    )
    DELIEVERTYPE = (
        ('0', u'下载'),
        ('1', u'光盘'),
        ('2', u'硬盘'),
        ('3', u'自由下载'),
    )
    ORDERSTATE = (
        ('2', u'已完成'),
        ('1', u'配送中'),
        ('0', u'准备中'),
    )
    ORDER = (
        ('0', u'已上传'),
        ('1', u'已归档'),
    )
    ORDERTYPE = (
        ('0', u'软件订单'),
        ('1', u'编组订单'),
    )
    softwareVersion = models.ForeignKey(
        SoftwareVersion,
        verbose_name=u"软件商品",
        on_delete=models.CASCADE,
        related_name='softwareVersion_order',
        null=True
    )
    group = models.ForeignKey(
        SoftwareGroup,
        verbose_name=u"软件编组订单",
        related_name='group_order',
        on_delete=models.CASCADE,
        null=True
    )
    softFile = models.ForeignKey(
        FileStore,
        verbose_name=u"下载文件",
        on_delete=models.CASCADE,
        related_name='order_softFile',
        null=True
    )
    user = models.ForeignKey(
        User,
        verbose_name=u"创建者",
        on_delete=models.CASCADE,
        related_name='software_founder',
    )
    examineState = models.CharField(
        verbose_name=u'新增订单',
        choices=EXAMINESTATE,
        max_length=20,
        default='0',
    )
    orderState = models.CharField(
        verbose_name=u'订单状态',
        choices=ORDERSTATE,
        max_length=20,
        default='0',
    )
    delieverType = models.CharField(
        verbose_name=u'配送方式',
        choices=DELIEVERTYPE,
        max_length=20,
        default=u'',
    )
    orderNumber = models.CharField(
        default=u'',
        verbose_name=u'订单号',
        max_length=32
    )
    orderType = models.CharField(
        default=u'0',
        verbose_name=u'订单类型',
        choices=ORDERTYPE,
        max_length=20,
    )
    isExamine = models.BooleanField(
        verbose_name=u'是否审核',
        default=False
    )
    orderUpState = models.CharField(
        verbose_name=u'新上传订单状态',
        choices=ORDER,
        max_length=20,
        default=0,
    )
    isDownload = models.BooleanField(
        verbose_name=u'是否允许下载',
        default=False
    )
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )

    def __unicode__(self):
        return self.createTime

    class Meta:
        ordering = ('createTime',)
